package scan
{
	/**
	 * Space in group to place other frames
	 */
	public class Space implements IFrame
	{
		////////////////////////////////////////////////////
		// 
		////////////////////////////////////////////////////
		
		private var _width:int;
		private var _height:int;
		
		private var _x:int;
		private var _y:int;
		
		private var _volume:int;
		private var _proportion:Number;
		
		private var _inactive:Boolean;
		
		////////////////////////////////////////////////////
		// 
		////////////////////////////////////////////////////
		
		public static function abs(value:int):int
		{
			return value < 0 ? value * -1 : value;
		}
		
		public static function min(a:int, b:int):int
		{
			return a < b ? a : b;
		}
		
		public static function max(a:int, b:int):int
		{
			return a > b ? a : b;
		}
		
		////////////////////////////////////////////////////
		// 
		////////////////////////////////////////////////////
		
		public function Space(x:int=0, y:int=0, width:int=0, height:int=0)
		{
			_x = x;
			_y = y;
			_width = width;
			_height = height;
			
			_volume = _width * _height;
			_proportion = width == 0 ? 1.0 : Number(_width) / Number(_height);
		}
		
		public function get width():int
		{
			return _width;
		}
		
		public function set width(value:int):void
		{
			if (value == _width)
				return;
			
			_width = value;
			_volume = _width * _height;
			_proportion = width == 0 ? 1.0 : Number(_width) / Number(_height);
		}
		
		public function get height():int
		{
			return _height;
		}
		
		public function set height(value:int):void
		{
			if (value == _height)
				return;
			
			_height = value;
			_volume = _width * _height;
			_proportion = width == 0 ? 1.0 : Number(_width) / Number(_height);
		}
		
		public function get x():int
		{
			return _x;
		}
		
		public function set x(value:int):void
		{
			if (value == _x)
				return;
			
			_x = value;
		}
		
		public function get y():int
		{
			return _y;
		}
		
		public function set y(value:int):void
		{
			if (value == _y)
				return;
			
			_y = value;
		}
		
		public function get volume():int
		{
			return _volume;
		}
		
		public function get proportion():Number
		{
			return _proportion;
		}
		
		public function get isLandscape():Boolean
		{
			return _proportion >= 1.0;
		}
		
		public function get isPortrait():Boolean
		{
			return _proportion < 1.0;
		}
		
		public function contains(frame:IFrame):Boolean
		{
			return x <= frame.x && y <= frame.y && x + width >= frame.x + frame.width && y + height >= frame.y + frame.height;
		}
		
		public function belongs(frame:IFrame):Boolean
		{
			return frame.x <= x && frame.y <= y && frame.x + frame.width >= x + width && frame.y + frame.height >= y + height;
		}
		
		public function fit(frame:IFrame):Boolean
		{
			return width >= frame.width && height >= frame.height;
		}
		
		public function clone():Space
		{
			return new Space(x, y, width, height);
		}
				
		public function get inactive():Boolean
		{
			return _inactive;
		}
		
		public function set inactive(value:Boolean):void
		{
			if (value == _inactive)
				return;
			
			_inactive  = value;
		}
	}
}